﻿using SIG.Core;
using SIG.Resources.Admin;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace SIG.Model
{
    public partial class Category : AuditableEntity<int>
    {

        public Category()
        {
            this.EntityName = EntityNames.Category;
            this.Products = new HashSet<Product>();         
        }

        [Display(Name = "分类名称", Prompt = "分类名称")]
        [Required(ErrorMessage = "请输入分类名称")]
        public string Title { get; set; }

        [Display(Name = "排序", Prompt = "排序")]
        [RegularExpression(@"^-?\d*$", ErrorMessage = "格式不正确")]
        public int Importance { get; set; }
        public string SeoName { get; set; }

        [Display(Name = "显示")]
        public bool Active { get; set; }

         public virtual ICollection<Product> Products { get; set; }
        public string ImageUrl { get; set; }

        [Display(Name = "父级分类")]
        public int? ParentId { get; set; }
        public virtual Category ParentCategory { get; set; }

        public virtual ICollection<Category> ChildCategories { get; set; }

        public string ParentCategoryTitle
        {
            get
            {
                if (this.ParentCategory != null)
                {
                    return this.ParentCategory.Title;
                }
                return string.Empty;
            }

        }
    }
}
